home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / stsim2.zip / SUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-01  |  4KB  |  166 lines

  1. Unit Sunit;
  2.  
  3. interface
  4.  
  5. type
  6.         date = record
  7.                         month:byte;
  8.                         day:byte;
  9.                         year:word;
  10.                end;
  11.  
  12.         dayptr = ^day;
  13.         day = record
  14.                 price:real;
  15.                 thing:integer; {
  16.                         1 to 9999 is stock,
  17.                         0 is player
  18.                         -99 is stock market average.
  19.                 }
  20.                 next:dayptr;
  21.               end;
  22.  
  23.         stock = record
  24.                         symbol : string[3];
  25.                         shares : integer;
  26.                 end;
  27.  
  28.         company = record
  29.                         name : string;
  30.                         symbol : string[3];
  31.                         cash : real;
  32.                         stock_price : real;
  33.                   end;
  34. var
  35.         universal_date:date;
  36.         first_one,current:dayptr;
  37.  
  38.         co:array[1..20] of company;
  39.         tmp_month:integer;
  40.         num_co:integer;
  41.         _flash:integer;
  42.         _flash_str:string;
  43.  
  44.  
  45. procedure flash;
  46. procedure input_stocks;
  47. procedure stock_window(x,y:integer);
  48. procedure earn;
  49. procedure init;
  50. procedure init_flash;
  51. procedure init_stocks;
  52.  
  53. implementation
  54. uses crt,menu;
  55.  
  56. procedure init;
  57. begin
  58.         clrscr;
  59.         box(2,2,79,24);
  60.         gotoxy(32,10);
  61.         write('Stock Simulation');
  62.  
  63.         gotoxy(27,20); write('press any key to continue');
  64.         clrscr;
  65.         with universal_date do begin
  66.                 month:=1;
  67.                 day:=1;
  68.                 year:=1900;
  69.         end;
  70.         new(first_one);
  71.         current:=first_one;
  72. end;
  73.  
  74. procedure input_stocks;
  75. var
  76.         m:file of company;
  77.         co:company;
  78.         i:integer;
  79.  
  80. begin
  81.         assign(m,'stock.sym');
  82.         rewrite(m);
  83.  
  84.         for i:=1 to 10 do begin
  85.                 with co do begin
  86.                         write('Name:');
  87.                          readln(name);
  88.                         write('Symbol:');
  89.                          readln(symbol);
  90.                         write('Cash:');
  91.                          readln(cash);
  92.                         write('Stock Price:');
  93.                          readln(stock_price);
  94.                         writeln('----------------> Next');
  95.                 end;
  96.                 write(m,co);
  97.         end;
  98.         close(m);
  99. end;
  100.  
  101.  
  102. procedure init_stocks;
  103. var
  104.         m:file of company;
  105. begin
  106.         assign(m,'stock.sym');
  107.         reset(m);
  108.  
  109.         num_co:=0;
  110.  
  111.         repeat
  112.                 inc(num_co);
  113.                 read(m,co[num_co]);
  114.         until eof(m);
  115.         close(m);
  116. end;
  117.  
  118. procedure init_flash;
  119. begin
  120.         _flash:=1;
  121.         _flash_str:='';
  122. end;
  123.  
  124. procedure flash;
  125. var
  126.         tmp_s:string;
  127. begin
  128.      if length(_flash_str)<70 then begin
  129.         str(co[_flash].stock_price:4:2,tmp_s);
  130.         _flash_str:= _flash_str+
  131.                      co[_flash].symbol+
  132.                      ' '+tmp_s+'   ';
  133.         inc(_flash);
  134.         if _flash>num_co then _flash:=1;
  135.      end;
  136.         delete(_flash_str,1,1);
  137.         gotoxy(1,1);
  138.         write(_flash_str);
  139. end;
  140.  
  141. procedure stock_window(x,y:integer);
  142. var i:integer;
  143. begin
  144.         gotoxy(x+1,y+1);
  145.         write('Symbol':8,'Price':8,'Cash':20);
  146.         for i:=1 to num_co do begin
  147.                 gotoxy(x+1,y+1+i);
  148.                 with co[i] do
  149.                 write(symbol:8,stock_price:8:3,(cash/1000000):20:3);
  150.         end;
  151. end;
  152.  
  153. procedure earn;
  154. var i:integer;
  155. begin
  156.         if universal_date.month<>tmp_month then begin
  157.                 for i:=1 to num_co do begin
  158.                         with co[i] do begin
  159.                                 cash:=cash+(cash*0.05)
  160.                         end;
  161.                 end;
  162.                 tmp_month:=universal_date.month;
  163.         end;
  164. end;
  165. end.
  166.